package com.erp.gather.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.erp.gather.domain.ErpCollectProductFreightTask;
import com.erp.gather.domain.bo.ErpCollectProductFreightTaskBo;
import com.erp.gather.domain.vo.ErpCollectProductFreightTaskVo;
import com.erp.gather.service.IErpCollectProductFreightTaskService;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Async;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 采集商品运费试算任务
 *
 * @author erp
 * @date 2023-04-20
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/gather/collectProductFreightTask")
public class ErpCollectProductFreightTaskController extends BaseController {

	private final IErpCollectProductFreightTaskService iErpCollectProductFreightTaskService;

	/**
	 * 查询采集商品运费试算任务列表
	 */
	@SaCheckPermission("gather:collectProductFreightTask:list")
	@GetMapping("/list")
	public TableDataInfo<ErpCollectProductFreightTaskVo> list(ErpCollectProductFreightTaskBo bo, PageQuery pageQuery) {
		return iErpCollectProductFreightTaskService.queryPageList(bo, pageQuery);
	}


	/**
	 * 获取采集商品运费试算任务详细信息
	 *
	 * @param id 主键
	 */
	@SaCheckPermission("gather:collectProductFreightTask:query")
	@GetMapping("/{id}")
	public R<ErpCollectProductFreightTaskVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
		return R.ok(iErpCollectProductFreightTaskService.queryById(id));
	}

	/**
	 * 新增采集商品运费试算任务
	 */
	@SaCheckPermission("gather:collectProductFreightTask:add")
	@Log(title = "采集商品运费试算任务", businessType = BusinessType.INSERT)
	@RepeatSubmit()
	@PostMapping()
	public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpCollectProductFreightTaskBo bo) {
		return toAjax(iErpCollectProductFreightTaskService.insertByBo(bo));
	}

	/**
	 * 修改采集商品运费试算任务
	 */
	@SaCheckPermission("gather:collectProductFreightTask:edit")
	@Log(title = "采集商品运费试算任务", businessType = BusinessType.UPDATE)
	@RepeatSubmit()
	@PutMapping()
	public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpCollectProductFreightTaskBo bo) {
		return toAjax(iErpCollectProductFreightTaskService.updateByBo(bo));
	}

	/**
	 * 删除采集商品运费试算任务
	 *
	 * @param ids 主键串
	 */
	@SaCheckPermission("gather:collectProductFreightTask:remove")
	@Log(title = "采集商品运费试算任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
		return toAjax(iErpCollectProductFreightTaskService.deleteWithValidByIds(Arrays.asList(ids), true));
	}


	@GetMapping("/addFreightTask")
	public R<List<Object>> addFreightTask(Long collectProductId, @RequestParam(defaultValue = "1") Integer type) {
		iErpCollectProductFreightTaskService.save(collectProductId, type);
		return R.ok();
	}

	@GetMapping("/refreshFreightTask")
	public R<List<Object>> refreshFreightTask(Long collectProductId, @RequestParam(defaultValue = "1") Integer type) {
		iErpCollectProductFreightTaskService.refresh(collectProductId, type);
		return R.ok();
	}



}
